package com.tonghe.controller;


import com.tonghe.domain.ResponseResult;
import com.tonghe.domain.dto.TagDto;
import com.tonghe.domain.entity.Tag;
import com.tonghe.enums.AppHttpCodeEnum;
import com.tonghe.service.MenuService;
import com.tonghe.service.TagService;
import com.tonghe.vo.PageVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;


/**
 * 菜单权限表(Menu)表控制层
 * @author makejava
 * @since 2022-09-03 15:01:50
 */
@RestController
@RequestMapping("content/tag")
public class TagController {

    @Autowired
    private TagService tagService;

    /** 查询标签列表 */
    @GetMapping("/list")
    public ResponseResult<PageVo> listTag(Integer pageNum, Integer pageSize, TagDto tagDto) {

        if( Objects.isNull(pageNum) || Objects.isNull(pageSize) || pageSize > 100 ) {
            return ResponseResult.errorResult(AppHttpCodeEnum.NO_OPERATOR_AUTH);
        }
        return tagService.pageTagList(pageNum,pageSize, tagDto);
    }

    /** 查询所有标签 */
    @GetMapping("/listAllTag")
    public ResponseResult listAllTag() {
        return tagService.getAllTag();
    }

    /** 查询标签详细 */
    @GetMapping("/{id}")
    public ResponseResult getTag(@PathVariable long id) {
        return tagService.selectOne(id);
    }

    /** 新增标签 */
    @PostMapping()
    public ResponseResult addTag(@RequestBody TagDto tagDto) {
        return tagService.insertTag(tagDto);
    }

    /** 修改标签 */
    @PutMapping()
    public ResponseResult updateTag(@RequestBody Tag tag) {
        return tagService.updateTag(tag);
    }

    /** 删除标签 */
    @DeleteMapping("/{id}")
    public ResponseResult delTag(@PathVariable long id) {
        return tagService.removeTagById(id);
    }



}

